package org.whuims.web.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.whuims.entity.Standard;
import org.whuims.service.standard.StandardService;

/**
 * Created by Roger on 2016/12/28.
 */
@Controller
@RequestMapping("/annotate")
public class AnnotateAdminController {

    @Autowired
    private StandardService standardService;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String edit(@PathVariable Long id, Model model) {
        model.addAttribute("std", standardService.getStandard(id));
        return "admin/annotate/edit";
    }

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    public HttpEntity<?> edit(Standard standard) {
        Standard oldStd = standardService.getStandard(standard.getId());
        if (oldStd != null) {
            oldStd.setTextOcr(standard.getTextOcr());
            standardService.save(oldStd);
        }
        return new ResponseEntity<Object>(HttpStatus.OK);
    }
}
